package com.hejjon.knowledgebase.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author:
 * @date: 2022-12-06 11:01:14
 * @since: 1.0
 */
public class ServletsUtil {


    public static final String BASE_REQUEST_PATH_PREFIX = "/ops/api";

    /**
     * 通过httpServletRequest获取ip
     *
     * @param request request
     * @return IP地址 可能为null
     */
    public static String getRemoteAddr(HttpServletRequest request) {
        if (request == null) {
            return null;
        }
        return request.getRemoteAddr();
    }

    public static void transfer(HttpServletResponse response, byte[] bs) throws IOException {
        Streams.transfer(Streams.toInputStream(bs), response.getOutputStream());
    }


}
